<template>
  <view class="content">
    <!-- 搜索 -->
    <div class="search-bar">
      <div class="scrolltop">
        <div class="search" @click="tosearch">
          <img
            src="../../static/images/icon/search.png"
            alt=""
            class="saerch-img"
          />
          <span class="search-text">搜索</span>
        </div>
      </div>
    </div>

    <view class="type">
      <!-- 左边切换 -->
      <ul class="left" ref="test">
        <li
          v-for="(item, index) in category"
          :key="index"
          @click="getRight(item.categoryId, index)"
          class="menu-item"
          :class="activeIndex == index ? 'active' : ''"
        >
          {{ item.categoryName }}
        </li>
      </ul>
      <!-- 右边数据 -->
      <ul class="right">
        <div class="adver-map">
          <div class="item-a" v-for="(item, index) in category" :key="index">
            <img
              v-if="creadid == item.categoryId"
              :src="item.pic"
              alt=""
              id="imgs"
            />
          </div>
        </div>
        <!-- 右边下面的数据 -->
        <div class="cont-item">
          <div
            class="show-item"
            v-for="(item, index) in rightlist"
            :key="index"
            @click="toProdDetails(item.prodId)"
          >
            <div class="more-prod-pic">
              <img :src="item.pic" alt="" class="more-pic" />
            </div>
            <div class="prod-text-right">
              <p class="prod-text more">{{ item.prodName }}</p>
              <p class="cate-prod-info">{{ item.brief }}</p>
              <div class=".prod-price.more">
                <span>￥</span>
                <span>{{ item.price }}</span>
                <span>.00</span>
              </div>
            </div>
          </div>
        </div>
      </ul>
    </view>
  </view>
</template>

<script>
import { gettypeList, getRightList } from "../../services/index";

export default {
  data() {
    return {
      title: "分类",
      category: [],
      rightlist: [],
      string: "",
      creadid: "",
      activeIndex: 0,
    };
  },
  onLoad() {
    this.categorys();
    this.getRight(85, 0);
  },

  methods: {
    async categorys() {
      let res = await gettypeList();

      this.category = res;
    },

    async getRight(categoryId, index) {
      let res = await getRightList(categoryId);

      this.rightlist = res.records;
      this.creadid = categoryId;

      this.activeIndex = index;
    },
    tosearch() {
      uni.navigateTo({
        url: "/pages/search-page/index",
      });
    },
    toProdDetails(id) {
      console.log(id);
      uni.navigateTo({
        url: `/pages/prod/prod?detailsId=${id}`,
      });
    },
  },
};
</script>

<style>
page {
  height: 100%;
  cursor: default;

  user-select: none;
  width: 100%;
  overflow-x: hidden;
}
.search {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60rpx;
  background: #fff;
  z-index: 1;
  border-radius: 50rpx;
  width: 92%;
  margin: auto;
  left: 4%;
  background: #f7f7f7;
}
.saerch-img {
  width: 32rpx;
  height: 32rpx;
  margin-right: 10rpx;
}
.search-text {
  display: block;
  font-size: 24rpx;
  color: #999;
}
.search-bar {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  color: #777;
  background: #fff;
  box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.07);
  z-index: 3;
  padding: 20rpx 0;
}
.content {
  display: flex;
  flex-direction: row;
  height: 100%;
  box-sizing: border-box;
  color: #333;
  font-family: helvetica, "Heiti SC", PingFangSC-Light;
}
.type {
  position: fixed;
  display: flex;
  overflow: hidden;
  margin-top: 100rpx;
  height: calc(100% - 100rpx);
}
.left {
  width: 200rpx;
  height: 100%;
  box-sizing: border-box;
  background-color: #f5f6f7;
  overflow: scroll;
  z-index: 2;
}
.right {
  width: 550rpx;
  height: 100%;
  box-sizing: border-box;
  background-color: #fff;
  z-index: 1;
  overflow: scroll;
}

.menu-item {
  line-height: 90rpx;
  height: 90rpx;
  text-align: center;
  border-bottom: 2rpx silid #e3e3e3;
  position: relative;
  color: #777;
  font-size: 28rpx;
}
.adver-map {
  width: auto;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
  margin: 30rpx 20rpx 0;
}
.cont-item {
  padding: 0 20rpx 20rpx 20rpx;
}
.show-item {
  position: relative;
  display: flex;
  justify-content: start;
  padding: 20rpx 0;
}
.more-prod-pic {
  text-align: center;
  width: 150rpx;
  height: 150rpx;
  line-height: 150rpx;
  font-size: 0;
}
.prod-text-right {
  margin-left: 20rpx;
  width: 75%;
}
.more-pic {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8rpx;
  vertical-align: middle;
}
image {
  width: 320px;

  display: inline-block;
  overflow: hidden;
}
.prod-text-right {
  margin-left: 20rpx;
  width: 75%;
}
.prod-text.more {
  margin: 0;
  font-size: 28rpx;
  display: -webkit-box;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  color: #000;
}
.cate-prod-info {
  font-size: 22rpx;
  color: #999;
  margin: 10rpx 0 20rpx 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}
.prod-price.more {
  font-size: 28rpx;
  color: #eb2444;
  font-family: arial;
}
.item-a {
  display: block;
  font-size: 0;
  width: 100%;
}
.item-a image {
  max-width: 100%;
}
#imgs {
  height: 146px;
  width: 100%;
}
.active {
  color: #eb2444;
  font-size: 28rpx;
  font-weight: bold;
  position: relative;
  background: #fff;
}
.menu-item.active:before {
  position: absolute;
  left: 0;
  content: "";
  width: 8rpx;
  height: 32rpx;
  top: 29rpx;
  background: #eb2444;
  background-image: initial;
  background-position-x: initial;
  background-position-y: initial;
  background-size: initial;

  background-attachment: initial;
  background-origin: initial;
  background-clip: initial;
  background-color: rgb(235, 36, 68);
}
</style>
